# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import scrapy

class MeiziPipeline:
    def process_item(self, item, spider):
        return item
# 导入专门的图片管道类
from scrapy.pipelines.images import ImagesPipeline
# 重写图片管道
class ImmagePipeline(ImagesPipeline):
#     专门对多媒体发送请求的方法
    def get_media_requests(self, item, info):
        res=scrapy.Request(item["link"],meta={"item":item})
        yield res
    def file_path(self, request, response=None, info=None, *, item=None):
        item=request.meta["item"]
        # 设置保存图片的名字 文件后缀
        name=item["title"]+".png"
        return name
    def item_completed(self, results, item, info):
        return item

